﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using DTO;
using System.Data;

namespace DAO
{
    public class CTDT_DAO
    {
        // load thông tin lên bảng
        public static DataTable LoadBangCTDT()
        {
            SqlConnection cnn = dbConnection.hamKetNoi();
            SqlCommand cmd = new SqlCommand("sploadTatCaCTDT", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dtb = new DataTable();
            da.Fill(dtb);
            return dtb;
        }
        //thêm mới chương trình đào tạo
        public static void themMoiCTDT(ChuongTrinhDT_DTO CTDT)
        {
            SqlConnection cnn = dbConnection.hamKetNoi();
            SqlCommand cmd = new SqlCommand("spThemCTDT", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaCTDT", SqlDbType.NChar, 10);
            cmd.Parameters.Add("@TenCTDT", SqlDbType.NVarChar, 50);
           // cmd.Parameters.Add("@MaTT", SqlDbType.NChar, 10);
            //gán giá trỊ
            cmd.Parameters["@MaCTDT"].Value = CTDT.MaCTDT;
            cmd.Parameters["@TenCTDT"].Value = CTDT.TenCTDT;
            //
            if (cnn.State == ConnectionState.Open)
                cnn.Close();
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
        //sửa thông tin chương trình đào tạo
        public static void SuaCTDT(ChuongTrinhDT_DTO CTDT)
        {
            SqlConnection cnn = dbConnection.hamKetNoi();
            SqlCommand cmd = new SqlCommand("spSuaCTDT", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaCTDT", SqlDbType.NChar, 10);
            cmd.Parameters.Add("@TenCTDT", SqlDbType.NVarChar, 50);
            //
            cmd.Parameters["@MaCTDT"].Value = CTDT.MaCTDT;
            cmd.Parameters["@TenCTDT"].Value = CTDT.TenCTDT;
            if (cnn.State == ConnectionState.Open)
            {
                cnn.Close();
            }
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
        //Xóa chương trình đào tạo
        public static void XoaCTDT(string ctdt)
        {
            SqlConnection cnn = dbConnection.hamKetNoi();
            SqlCommand cmd = new SqlCommand("spXoaTatCaCTDT", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaCTDT", SqlDbType.NChar, 10);
            //
            cmd.Parameters["@MaCTDT"].Value = ctdt;
            //
            if (cnn.State == ConnectionState.Open)
            {
                cnn.Close();
            }
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
    }
}